package com.kotiln.lgc.lib_network.http

import com.kotiln.lgc.lib_network.interceptor.HttpInterceptor
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 *@fileName ServiceCreator
 *@date2021/1/25  17:27
 *@author ServiceCreator$
 *@describe TODO
 *@desc 网络请求构建器  Jetpack
 */
object ServiceCreator {

    //创建客户端
    private fun getClient(): OkHttpClient {
        return OkHttpClient.Builder().addInterceptor(HttpInterceptor()).build()
    }
    //Retrofit构建器
    private val retrofit=
        Retrofit.Builder().baseUrl(HttpUrl.KIND_BASE_URL)/*.client(getClient())*/.addConverterFactory(GsonConverterFactory.create()).build()

    //泛型实化
    inline fun<reified T>create():T=create(T::class.java)

    fun <T> create(serviceClass:Class<T>):T=retrofit.create(serviceClass)
}